import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:banquanjie_app/app/services/HttpsRequest.dart';

class WorkDetailController extends GetxController with GetSingleTickerProviderStateMixin {
  late TabController tabController;
  final HttpsClient httpsClient = HttpsClient();
  final RxMap info = {}.obs;
  final RxList wrapper = [].obs;
  final count = 0.obs;
  final RxString timeLong = ''.obs;
  
  @override
  void onInit() {
    tabController = TabController(length: 4, vsync: this);
    super.onInit();
    fnGet();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }
  String getTimeLongStr(info) {
    var worksTypeFirst =  info.value['Works']['worksTypeFirst'];
    var timeLong1 =  info.value['Works']['timeLong'];
    var word = worksTypeFirst == 198 ? '每期' : worksTypeFirst == 196 || worksTypeFirst == 201 ? '' : '每集';
    return '$word$timeLong1分钟';
  }
 

  void fnGet() async{
    var result = await httpsClient.post('/works/works/worksInfo', { "id": "1394" });
    if (result.data['code'] == 200) {
      info.value = result.data['data'];
      wrapper.value = [
        ...result.data['data']['worksPosters'].map((item) => item['worksPosterUrl']).toList(),
        ...result.data['data']['worksRelevantPerformers'].map((item) => item['performerOssUrl']).toList(),
        ...result.data['data']['worksDirectorInfos'].map((item) => item['directorImgUrl']).toList(),
        ...result.data['data']['worksWriterInfos'].map((item) => item['writerImgUrl']).toList(),
      ];
      timeLong.value = getTimeLongStr(info);
      update();
    }
  }
}
